//
//  EquipModelInfo.m
//  SpaceStorm
//
//  Created by 祥 雍 on 13-5-26.
//  Copyright (c) 2013年 __MyCompanyName__. All rights reserved.
//
//  装备模型表的信息类//缺宽和高

#import "EquipModelInfo.h"
#import "Variable.h"

@implementation EquipModelInfo

@synthesize equipModelId = _equipModelId;
@synthesize equipModelBig = _equipModelBig;
@synthesize equipModelMid = _equipModelMid;
@synthesize equipModelSmall = _equipModelSmall;
@synthesize level = _level;
@synthesize groupId = _groupId;
@synthesize name = _name;
@synthesize width = _width;
@synthesize height = _height;
@synthesize anchorPoint = _anchorPoint;
@synthesize bulletId = _bulletId;
@synthesize actionId = _actionId;

+(id) infoWithTbxml:(TBXMLElement *)tbxml
{
    return [[[self alloc] initWithTbxml:tbxml] autorelease]; 
}

-(id) initWithTbxml:(TBXMLElement *)tbxml
{
    self = [super init]; 
	
	if (self!= nil) 
    {
        //装备模型id	
        self.equipModelId = [[TBXML valueOfAttributeNamed:@"id" forElement:tbxml] intValue];
        if(showXMLLog == YES) CCLOG(@"装备模型id:%d", self.equipModelId);
        
        //装备模型大类	
        self.equipModelBig = [[TBXML valueOfAttributeNamed:@"equipModelBig" forElement:tbxml] intValue];
        if(showXMLLog == YES) CCLOG(@"装备模型大类:%d", self.equipModelBig);
        
        //装备模型中类	
        self.equipModelMid = [[TBXML valueOfAttributeNamed:@"equipModelMid" forElement:tbxml] intValue];
        if(showXMLLog == YES) CCLOG(@"装备模型中类:%d", self.equipModelMid);
        
        //装备模型细类	
        self.equipModelSmall = [[TBXML valueOfAttributeNamed:@"equipModelSmall" forElement:tbxml] intValue];
        if(showXMLLog == YES) CCLOG(@"装备模型细类:%d", self.equipModelSmall);
        
        //科技等级
        self.level = [[TBXML valueOfAttributeNamed:@"level" forElement:tbxml] intValue];
        if(showXMLLog == YES) CCLOG(@"科技等级:%d", self.level);
        
        //小组编号	
        self.groupId = [[TBXML valueOfAttributeNamed:@"groupId" forElement:tbxml] intValue];
        if(showXMLLog == YES) CCLOG(@"小组编号:%d", self.groupId);
        
        //模型名	
        self.name = [TBXML valueOfAttributeNamed:@"name" forElement:tbxml];
        if(showXMLLog == YES) CCLOG(@"模型名:%@", self.name);
        
        //模型的宽
        self.width = [[TBXML valueOfAttributeNamed:@"width" forElement:tbxml] floatValue];
        if(showXMLLog == YES) CCLOG(@"width:%f", self.width);
        
        //模型的高
        self.height = [[TBXML valueOfAttributeNamed:@"height" forElement:tbxml] floatValue];
        if(showXMLLog == YES) CCLOG(@"height:%f", self.height);
        
        //轴心坐标	
        NSString * x;
        NSString * y;
        NSArray *array;
        NSString * anchorPoint = [TBXML valueOfAttributeNamed:@"anchorPoint" forElement:tbxml];
        if([anchorPoint isEqualToString: @"0"] == NO)//非0保护
        {
            array = [anchorPoint componentsSeparatedByString:@","]; 
            x = [array objectAtIndex:0];
            y = [array objectAtIndex:1];
            self.anchorPoint = ccp([x floatValue] / self.width, (1 - [y floatValue] / self.height));
            if(showXMLLog == YES) CCLOG(@"重心坐标（导弹用:%f,%f", [x floatValue], [y floatValue]);
        }
        else
        {
            self.anchorPoint = CGPointZero;
        }
        //弹药id
        self.bulletId = [[TBXML valueOfAttributeNamed:@"bulletId" forElement:tbxml] intValue];
        if(showXMLLog == YES) CCLOG(@"弹药id:%d", self.bulletId);
        
        //动作脚本
        self.actionId = [[TBXML valueOfAttributeNamed:@"actionId" forElement:tbxml] intValue];
        if(showXMLLog == YES) CCLOG(@"动作脚本:%d", self.actionId);
    }
    
    return self;
}

@end
